home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / System7 tools / Frontier / Frontier SDK 2.1 / Toolkits / Applet Toolkit / appletfont.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-11  |  5.6 KB  |  320 lines  |  [TEXT/KAHL]

  1.  
  2. /*© Copyright 1988-1992 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4.  
  5. #include "appletdefs.h"
  6. #include "appletstrings.h"
  7. #include "appletfont.h"
  8.  
  9.  
  10. #define styleseparator "\p+"
  11.  
  12. FontInfo globalfontinfo;
  13.  
  14. #define ctstyles 7 
  15.  
  16. short stylesarray [ctstyles] = 
  17.     
  18.     {0, bold, italic, underline, 
  19.     
  20.     bold + italic, bold + underline, 
  21.     
  22.     italic + underline};
  23.  
  24.  
  25.  
  26.  
  27. void setfontsizestyle (short fontnum, short fontsize, short fontstyle) {
  28.  
  29.     TextFont (fontnum);
  30.     
  31.     TextSize (fontsize);
  32.     
  33.     TextFace (fontstyle);
  34.     } /*setfontsizestyle*/
  35.     
  36.     
  37. void setglobalfontsizestyle (short fontnum, short fontsize, short fontstyle) {
  38.  
  39.     setfontsizestyle (fontnum, fontsize, fontstyle);
  40.     
  41.     GetFontInfo (&globalfontinfo);
  42.     } /*setglobalfontsizestyle*/
  43.     
  44.     
  45. short setnamedfont (bigstring bs, short fsize, short fstyle, short defaultfont) {
  46.  
  47.     /*
  48.     give me the name of a font you like.  I'll try to set to that font,
  49.     but if its not available, you get the default font.  be sure to select
  50.     a default font that is mandatory -- like geneva or newYork.
  51.     */
  52.     
  53.     short fontnum;
  54.     
  55.     GetFNum (bs, &fontnum);
  56.     
  57.     if (fontnum == 0) 
  58.         fontnum = defaultfont; /*use caller's second choice*/
  59.         
  60.     setglobalfontsizestyle (fontnum, fsize, fstyle);
  61.     
  62.     return (fontnum); /*return the font that we are actually using*/
  63.     } /*setnamedfont*/
  64.         
  65.  
  66. void getfontsizestyle (short *fontnum, short *fontsize, short *fontstyle) {
  67.  
  68.     *fontnum = (*quickdrawglobal (thePort)).txFont;
  69.     
  70.     *fontsize = (*quickdrawglobal (thePort)).txSize;
  71.     
  72.     *fontstyle = (*quickdrawglobal (thePort)).txFace;
  73.     } /*getfontsizestyle*/
  74.     
  75.     
  76. void getstyle (short style, short *flplain, short *flbold, short *flitalic, short *flunderline, short *floutline, short *flshadow) {
  77.  
  78.     /*
  79.     give me a style bit array, and I'll extract the booleans which are 
  80.     slightly easier to deal with.
  81.     
  82.     if none of the others are true, we set flplain to true.  otherwise 
  83.     flplain is false.
  84.     */
  85.  
  86.     *flplain = true;  /*default values*/
  87.     
  88.     *flbold = false;
  89.     
  90.     *flitalic = false;
  91.     
  92.     *flunderline = false;
  93.     
  94.     *floutline = false;
  95.     
  96.     *flshadow = false;
  97.     
  98.     if (style >= shadow) {
  99.         
  100.         style -= shadow;
  101.         
  102.         *flshadow = true;
  103.         
  104.         *flplain = false;
  105.         }
  106.         
  107.     if (style >= outline) {
  108.         
  109.         style -= outline;
  110.         
  111.         *floutline = true;
  112.         
  113.         *flplain = false;
  114.         }
  115.         
  116.     if (style >= underline) {
  117.         
  118.         style -= underline;
  119.         
  120.         *flunderline = true;
  121.         
  122.         *flplain = false;
  123.         }
  124.         
  125.     if (style >= italic) {
  126.         
  127.         style -= italic;
  128.         
  129.         *flitalic = true;
  130.         
  131.         *flplain = false;
  132.         }
  133.         
  134.     if (style >= bold) {
  135.         
  136.         style -= bold;
  137.         
  138.         *flbold = true;
  139.         
  140.         *flplain = false;
  141.         }
  142.     } /*getstyle*/
  143.     
  144.  
  145. void checkstyle (boolean fl, bigstring bsin, bigstring bsout) {
  146.  
  147.     if (fl) {
  148.         if (bsout [0]) { /*already something on the output string*/
  149.         
  150.             pushstring (styleseparator, bsout);
  151.             
  152.             pushstring (bsin, bsout);
  153.             }
  154.         else
  155.             copystring (bsin, bsout);
  156.         }
  157.     } /*checkstyle*/
  158.         
  159.  
  160. short getfontheight (void) {
  161.     
  162.     FontInfo info;
  163.     
  164.     GetFontInfo (&info);
  165.     
  166.     return (info.ascent + info.descent);
  167.     } /*getfontheight*/
  168.     
  169.     
  170. void fontgetname (short fontnum, bigstring fontname) {
  171.     
  172.     GetFontName (fontnum, fontname);
  173.     } /*fontgetname*/
  174.  
  175.  
  176. void fontgetnumber (bigstring fontname, short *fontnum) {
  177.     
  178.     if (stringlength (fontname) == 0)
  179.         *fontnum = geneva;
  180.     else
  181.         GetFNum ((ptrstring) fontname, fontnum);
  182.     } /*fontgetnumber*/
  183.     
  184.  
  185. void diskgetfontname (short fontnum, diskfontstring fontname) {
  186.     
  187.     /*
  188.     Apple recommends that fonts be stored on disk as strings.  we return the
  189.     fontname, limited in length to 32, based on the indicated font number.
  190.     */
  191.     
  192.     bigstring bs;
  193.     
  194.     GetFontName (fontnum, bs);
  195.     
  196.     if (stringlength (bs) > diskfontnamelength)
  197.         setstringlength (bs, diskfontnamelength);
  198.     
  199.     copystring (bs, (ptrstring) fontname);
  200.     } /*diskgetfontname*/
  201.  
  202.  
  203. void diskgetfontnum (diskfontstring fontname, short *fontnum) {
  204.     
  205.     if (stringlength (fontname) == 0)
  206.         *fontnum = geneva;
  207.     else
  208.         GetFNum ((ptrstring) fontname, fontnum);
  209.     } /*diskgetfontnum*/
  210.     
  211.  
  212. void getnextfont (short *fontnum) {
  213.     
  214.     /*
  215.     register MenuHandle hmenu = hdlfontmenu;
  216.     register short i, ctitems;
  217.     bigstring fontname, bs;
  218.     
  219.     GetFontName (*fontnum, fontname);
  220.     
  221.     ctitems = CountMItems (hmenu);
  222.     
  223.     for (i = 1; i <= ctitems; i++) {
  224.         
  225.         GetItem (hmenu, i, bs);
  226.         
  227.         if (unicaseequalstrings (bs, fontname)) {
  228.             
  229.             if (i == ctitems)
  230.                 GetItem (hmenu, 1, fontname);
  231.             else
  232.                 GetItem (hmenu, i + 1, fontname);
  233.                 
  234.             GetFNum (fontname, fontnum);
  235.                 
  236.             return;
  237.             }
  238.         } /%for%/
  239.         
  240.     *fontnum = applFont; /%the input font isn't on this system%/
  241.     */
  242.     } /*getnextfont*/
  243.     
  244.     
  245. void getprevfont (short *fontnum) {
  246.     
  247.     /*
  248.     register MenuHandle hmenu = hdlfontmenu;
  249.     register short i, ctitems;
  250.     bigstring fontname, bs;
  251.     
  252.     GetFontName (*fontnum, fontname);
  253.     
  254.     ctitems = CountMItems (hmenu);
  255.     
  256.     for (i = 1; i <= ctitems; i++) {
  257.         
  258.         GetItem (hmenu, i, bs);
  259.         
  260.         if (unicaseequalstrings (bs, fontname)) {
  261.             
  262.             if (i == 1)
  263.                 GetItem (hmenu, ctitems, fontname);
  264.             else
  265.                 GetItem (hmenu, i - 1, fontname);
  266.                 
  267.             GetFNum (fontname, fontnum);
  268.                 
  269.             return;
  270.             }
  271.         } /%for%/
  272.         
  273.     *fontnum = applFont; /%the input font isn't on this system%/
  274.     */
  275.     } /*getprevfont*/
  276.     
  277.     
  278. void getnextstyle (short *style) { 
  279.     
  280.     register short i;
  281.     
  282.     for (i = 0; i < ctstyles; i++) {
  283.         
  284.         if (*style == stylesarray [i]) {
  285.             
  286.             if (i == (ctstyles - 1)) 
  287.                 *style = stylesarray [0];
  288.             else
  289.                 *style = stylesarray [i + 1];
  290.                 
  291.             return;
  292.             }
  293.         } /*for*/
  294.         
  295.     *style = stylesarray [0];
  296.     } /*getnextstyle*/
  297.     
  298.     
  299. void getprevstyle (short *style) { 
  300.     
  301.     register short i;
  302.     
  303.     for (i = 0; i < ctstyles; i++) {
  304.         
  305.         if (*style == stylesarray [i]) {
  306.             
  307.             if (i == 0) 
  308.                 *style = stylesarray [ctstyles - 1];
  309.             else
  310.                 *style = stylesarray [i - 1];
  311.             
  312.             return;
  313.             }
  314.         } /*for*/
  315.         
  316.     *style = stylesarray [0];
  317.     } /*getprevstyle*/
  318.     
  319.     
  320.